﻿import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 2.12
import QtMultimedia 5.14

Window {
    title: "注射器维护"
    width: 800*dp
    height: 650*dp
    maximumWidth: 800*dp
    maximumHeight: 650*dp
    minimumWidth: 800*dp
    minimumHeight: 650*dp
    Rectangle{
        id:zsqta
        x:0*dp
        //                        y:80*dp
        width: parent.width
        height: parent.height
        color: "#F9F9F9"
        Row{
            y:20*dp
            spacing: 10*dp
            anchors.right: parent.right
            PushButton{
                defaultMode1: true
                title: "新建"
                width: 120*dp
                height: 40*dp
                onReleased: {
                    newtype.mltype="0"
                    //                                    newtype.tablemodeldata=
                    //                                    newtype.hcna=""
                    newtype.indextype=CMaintenance.getSerial()
                    newtype.zsqsum=6
                    //                                    newtype.tablemodeldata=[]
                    newtype.hcmod=CMaintenance.canInsertConsumablesType()
                    if(newtype.hcmod.length===0){
                        maintenanceToast.show("耗材均已新建完毕",0)
                        return
                    }
                    newtype.zsqsum=CMaintenance.getSyringNum(CMaintenance.canInsertConsumablesType()[0])
                    // 定义二维数组的行数和列数
                    var rows = CMaintenance.getSyringNum(CMaintenance.canInsertConsumablesType()[0]);
                    // 创建一个空的二维数组
                    var twoDArray = [];
                    // 使用嵌套循环初始化二维数组
                    for (var i = 0; i < rows; i++) {
                        // 为每一行创建一个新的数组
                        twoDArray[i] = ["",CExeConfig.getzsqdef()[0],CExeConfig.getnj(CExeConfig.getzsqdef()[0]),"","","","mL/Min","1:1","0.6096",
                                        "3200","",""];
                    }
                    newtype.tablemodeldata=twoDArray
                    newtype.show()
                }
            }
            PushButton{
                defaultMode1: true
                title: "全部删除"
                width: 120*dp
                height: 40*dp
                onReleased: {
                    qbsc.show()
                }
            }
            PushButton{
                defaultMode1: true
                title: "导入"
                width: 120*dp
                height: 40*dp
                CustomTooltip{
                    visible: parent.isHover
                    text: "如果导入的耗材已存在，原有的耗材信息将会被覆盖"
                }
                onReleased: {
                    var data=CMaintenance.importSyringConfig()
                    if(data===0){
                        maintenanceToast.show("导入成功",0)
                    }
                    else if(data===-1){
                        maintenanceToast.show("文件不存在",1)
                    }
                    else if(data===-2){
                        maintenanceToast.show("导入文件数据格式不正确",1)
                    }
                    modelist.tableData=CMaintenance.getSyringInfo()
                }
            }
        }
        CustomTableList{
            id:modelist
            x:20*dp
            y:80*dp
            width: parent.width-40*dp
            height: parent.height-80*dp
            //                        showCheckedBox: true
            title: ["序号", "耗材名称", "注射器数量", "最后修改时间"]
            showHGridLine: true     // 显示横向网格线
            showOperateButton: true
            //                        showOperateButton2: true
            tableData: CMaintenance.getSyringInfo()
            operateButtonWidth:100*dp
            onOperate: {
                if(text==="1"){
                    newtype.mltype="1"
                    newtype.indextype=num
                    newtype.tablemodeldata=CMaintenance.getSyringDetails(hcname)
                    newtype.hcmod=[hcname]
                    newtype.zsqsum=CMaintenance.getSyringNum(hcname)
                    newtype.show()
                }else if(text==="2"){
                    if(CMaintenance.delSyring(num)){
                        maintenanceToast.show("删除成功",0)
                    }else{
                        maintenanceToast.show("已经在实验配置中使用不允许删除",1)
                    }
                    modelist.tableData=CMaintenance.getSyringInfo()
                }else if(text==="3"){
                    CMaintenance.setDefault(num)
                    modelist.tableData=CMaintenance.getSyringInfo()
                }else if(text==="4"){
                    CMaintenance.exportSyringConfig(hcname)
                    maintenanceToast.show("导出成功",0)
                }
            }
        }
    }
}
